class Coord
	include Comparable
	
	attr_accessor :x, :y, :z
	
	def initialize(*nums)
		if(nums.size > 3) 
			raise ArgumentError("Too many arguments")
		end
		if(nums.size < 1) 
			raise ArgumentError("Must have at least one argument")
		end
		
		@x = nums[0].to_f
		@y = nums[1].to_f || 0
		@z = nums[2].to_f || 0
	end
	
	def +(other)
		Coord.new(@x + other.x, @y + other.y, @z + other.z)
	end
	
	def -(other)
		Coord.new(@x - other.x, @y - other.y, @z - other.z)
	end
	
	def to_s
		"(#{@x}, #{@y}, #{@z})"
	end
	
	def <=>(other)
		if(@x == other.x) && (@y == other.y) && (@z == other.z) 
			return 0
		else
			if ( ((@x + @y + @z)/3) > ((other.x + other.y + other.z)/3) )
				return 1
			else
				return -1
			end
		end
	end
	
	def distance_to(other)
		Math.sqrt((@x-other.x)**2 + (@y-other.y)**2 + (@z-other.z)**2)	
	end

end


if $0 == __FILE__
	puts "hello"
end
